﻿using System;
using System.IO;

namespace SimpleTFTP
{
    internal class ReadWritePacket : BasePacket
    {
        public string FileName { get; set; }

        public string Mode { get; set; }

        public ReadWritePacket(byte[] data)
        {
            /*
             * must read packet:
             * - op code (2 bytes) short/int16
             * - filename (zero-terminated)
             * - mode (zero-terminated)
             */

            using (MemoryStream ms = new MemoryStream(data))
            {
                OpCode = (OpCode)Utilities.ReadInt16(ms);
                FileName = Utilities.ReadZString(ms);
                Mode = Utilities.ReadZString(ms);
            }
        }

        public override byte[] ToByteArray()
        {
            // TODO
            throw new NotImplementedException();
        }
    }
}